//T(n) = T(n-1) + T(n-2) + T(n-3)
#include <vector>
#include <cassert>
#include <iostream>
//T(1) = 1, T(2) = 2; T(3) = 4
//Time = exp(n), Space = O(n)
int recursive_naive(int n){
	assert(n>0);
	if (n == 1)
		return 1;
	if (n == 2)
		return 2;
	if (n == 3)
		return 4;
	return recursive_naive(n-1) + recursive_naive(n-2) + recursive_naive(n-3);
}
//Time = O(n), Space = O(n)
int recursive_memoized(int n, std::vector<int>& a) {
	assert(n>0);
	if (n == 1)
		return 1;
	if (n == 2)
		return 2;
	if (n == 3)
		return 4;
	if (a[n] > 0)
		return a[n];
	else {
		a[n] = recursive_memoized(n-1,a) + recursive_memoized(n-2,a) + recursive_memoized(n-3,a);
		return a[n];
	}
}
//Time = O(1), Space = O(1)
int iterative(int n){
	if (n == 1)
		return 1;
	if (n == 2)
		return 2;
	if (n == 3)
		return 4;
	int t0 = 1, t1 = 2, t2 = 4;
	int t3;
	for (int i = 4; i <= n; ++i) {
		t3 = t2 + t1 + t0;
		t0 = t1;
		t1 = t2;
		t2 = t3;
	}
	return t3;
}

void test_9_1(){
	int n;
	while(std::cin >> n){
		std::vector<int> a(n+1);
		std::cout << recursive_naive(n) << std::endl;
		std::cout << recursive_memoized(n,a) << std::endl;
		std::cout << iterative(n) << std::endl;
	}
}